package com.estate.business.impl;

import java.util.HashMap;
import java.util.List;

import com.estate.business.DocumentService;
import com.estate.dao.DocumentDao;
import com.estate.dao.EfileDao;
import com.estate.dao.FileDeleteDao;
import com.estate.dao.LendDocumentDao;
import com.estate.vo.Vo;
import com.estate.vo.impl.DocumentVo;
import com.estate.vo.impl.EfileVo;
import com.estate.vo.impl.FileDeleteVo;
import com.estate.vo.impl.LendDocumentVo;

public class DocumentServiceImpl implements DocumentService {
	
	private DocumentDao documentDao;
	private EfileDao efileDao;
	private FileDeleteDao fileDeleteDao;
	private LendDocumentDao lendDocumentDao;

	public void addDocument(DocumentVo vo) {
		// TODO Auto-generated method stub
		documentDao.addVo(vo);
		
	}

	public void deleteByPK(int id) {
		// TODO Auto-generated method stub
		Vo vo=documentDao.findByPK(id);
		List<EfileVo> voList=efileDao.findByDocumentId(id);
		for(int i=0;i<voList.size();i++){
			FileDeleteVo deleteVo=new FileDeleteVo();
			deleteVo.setFilePath(voList.get(i).getFilePath());
			fileDeleteDao.addVo(deleteVo);
			efileDao.deleteVo(voList.get(i));
		}
		List<LendDocumentVo> lendVoList=lendDocumentDao.findByDocumentId(id);
		for(int i=0;i<lendVoList.size();i++){
			lendDocumentDao.deleteVo(lendVoList.get(i));
		}
		documentDao.deleteVo(vo);
		
	}

	public List<DocumentVo> findAllDocument() {
		// TODO Auto-generated method stub
		return documentDao.findAllDocument();
	}

	public Vo findByPK(int id) {
		// TODO Auto-generated method stub
		return documentDao.findByPK(id);
	}

	public void update(Vo vo) {
		// TODO Auto-generated method stub
		documentDao.updateVo(vo);
	}

	public void setDocumentDao(DocumentDao documentDao) {
		this.documentDao = documentDao;
	}

	public DocumentDao getDocumentDao() {
		return documentDao;
	}

	public HashMap<Integer, String> findAllIdAndName() {
		// TODO Auto-generated method stub
		System.out.println("a");
		List<DocumentVo> voList=documentDao.findAllDocument();
		HashMap<Integer,String> map=new HashMap<Integer,String>();
		for(int i=0;i<voList.size();i++){
			map.put(voList.get(i).getId(), voList.get(i).getDocumentName());
			System.out.println(voList.get(i).getId());
		}
		return map;
	}

	public List<DocumentVo> findByLendState(int lendState) {
		// TODO Auto-generated method stub
		return documentDao.findByLendState(lendState);
	}

	public void deleteByLibraryId(int id) {
		// TODO Auto-generated method stub
		List<DocumentVo> voList=documentDao.findByLibraryId(id);
		for(int i=0;i<voList.size();i++){
			documentDao.deleteVo(voList.get(i));
		}
	}

	public void setEfileDao(EfileDao efileDao) {
		this.efileDao = efileDao;
	}

	public EfileDao getEfileDao() {
		return efileDao;
	}

	public void setFileDeleteDao(FileDeleteDao fileDeleteDao) {
		this.fileDeleteDao = fileDeleteDao;
	}

	public FileDeleteDao getFileDeleteDao() {
		return fileDeleteDao;
	}

	public void setLendDocumentDao(LendDocumentDao lendDocumentDao) {
		this.lendDocumentDao = lendDocumentDao;
	}

	public LendDocumentDao getLendDocumentDao() {
		return lendDocumentDao;
	}

}
